function loaded () {
    var myScroll,
        upIcon = $("#up-icon"),
        downIcon = $("#down-icon"),
        distance = 30; //滑动距离
    
	var url = '${base}/${url}';					// call API
	var param = {value1: 0, limit: 2, offset: 0};

    myScroll = new IScroll('#wrapper', { probeType: 3, mouseWheel: true });

    myScroll.on("scroll",function(){
        var y = this.y,
            maxY = this.maxScrollY - y,
            downHasClass = downIcon.hasClass("reverse_icon"),
            upHasClass = upIcon.hasClass("reverse_icon");

        if(y >= distance){
            !downHasClass && downIcon.addClass("reverse_icon");
            return "";
        }else if(y < distance && y > 0){
            downHasClass && downIcon.removeClass("reverse_icon");
            return "";
        }

        if(maxY >= distance){
            !upHasClass && upIcon.addClass("reverse_icon");
            return "";
        }else if(maxY < distance && maxY >=0){
            upHasClass && upIcon.removeClass("reverse_icon");
            return "";
        }
    });
    
    function upAjax() {
        $.ajax({
            type: 'GET',
            url: url,
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            dataType: "json",
            contentType: "application/json; charset=utf-8",
        }).done(function(result) {
			if (result.total > 0) {
            	var str = '';
	    		for (var i = 0; i < result.rows.length; i++) {
	    			str += '\
	    				<li class="x-col-1 with-border">\
		               		<div class="x-plain x-clearfix">\
			           			<div class="x-thumb x-pull-left x-m-r-10">\
			           				<a href="javascript:;" onclick="goDetail(' + result.rows[i].id + ')">\
			           				<img src="' + (result.rows[i].bigpic == '' ? '${base}/ftl/img/nopic128.png' : result.rows[i].bigpic) + '" class="img-responsive" alt="">\
			           				</a>\
			           			</div>\
			           			<div class="x-info">\
			           				<a href="javascript:;" onclick="goDetail(' + result.rows[i].id + ')" class="x-block">\
										<span class="x-info-title">' + result.rows[i].title + '</span>\
										<span class="x-info-summary">' + result.rows[i].author + '</span>\
										<span class="x-info-summary">' + result.rows[i].translator + '</span>\
										<span class="x-info-summary">总数: ' + result.rows[i].total + '</span>\
                                        <span class="x-info-summary">剩余: ' + result.rows[i].remain + '</span>\
									</a>\
			           			</div>\
			       			</div>\
	    		        </li>\
	    			';
	    		}
	    		
	    	//	$('#scroller-content ul').append(content);
	    		$("#book_list").append(str);
            	param.offset = param.offset + param.limit;
                myScroll.refresh(result.total);
			}
        }).fail(function() {
            document.getElementById('list').innerHTML = "<font style='font-size:0.16rem;'>数据请求失败，请重新刷新</font>";
        });
    }

    function downAjax() {
    //	console.log("downAjax!!!");
    	/*
        var params = '{"params":{"shopType":"0","sort":"0","cityId":"1","pageRows":"10","deviceType":"MX4","toPage":"1","userX":"118.790609","userY":"32.047616","filter":"0"}}';
        $.ajax({
            type: "post",
            url: "url",
            data: params,
            crossDomain: true,
            xhrFields: {
                withCredentials: true
            },
            dataType: "json",
            contentType: "application/json; charset=utf-8"
        }).done(function(d) {
            if (d && d.response.shopList.length > 0) {
                console.log(d.response.shopList);
                var content = "";
                for(var i=0,len=d.response.shopList.length;i<len;i++){
                    content += "<li>"+ d.response.shopList[i].shopName +"</li>"
                }
                $('#scroller-content ul').prepend(content);
                myScroll.refresh(d.response.page.pageAmount);
            }
        }).fail(function() {
            document.getElementById('list').innerHTML = "<font style='font-size:0.16rem;'>数据请求失败，请重新刷新</font>";
        })*/
    }
    
    // 下拉刷新事件
    myScroll.on("slideDown",function(){
        if(this.y > distance){
            downAjax();
            upIcon.removeClass("reverse_icon")
        }
    });
    
    // 上拉滑动事件
    myScroll.on("slideUp",function(){
        if(this.maxScrollY - this.y > distance){
            upAjax();
            upIcon.removeClass("reverse_icon")
        }
    });
}
loaded ();